package com.troila.cloud.simplify.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.troila.cloud.simplify.model.SAnswer;
import com.troila.cloud.simplify.repository.SAnswerRepository;

@Service
@Transactional
public class SAnswerService {
	
	@Autowired
	private SAnswerRepository sAnswerRepository;
	
	public void delAnswer(int id) {
		sAnswerRepository.delete(id);
	}
	
	public void answerNum(int id) {
		SAnswer sAnswer = sAnswerRepository.findOne(id);
		if(sAnswer != null) {
			sAnswer.setSelectNum(sAnswer.getSelectNum()+1);
			sAnswerRepository.save(sAnswer);
		}
	}
	public void save(List<SAnswer> sAnswers) {
		for (int i = 0; i < sAnswers.size(); i++) {
			sAnswerRepository.save(sAnswers.get(i));
		}
	}
	
	public List<SAnswer> findByATitleId(int sTitleId){
		return sAnswerRepository.findBySTitleId(sTitleId);
	}

}